
//
//  MCMMDetailPopView.m
//  TLYL
//
//  Created by miaocai on 2017/10/26.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMMDetailPopView.h"
#import "MCGroupPaymentModel.h"
#import "MCRecordTool.h"


@interface MCMMDetailPopView()

@property (nonatomic,weak) UILabel *dingDanNumberLabel;
@property (nonatomic,weak) UILabel *dingDanDetailLabel;
@property (nonatomic,weak) UILabel *jinELabel;
@property (nonatomic,weak) UILabel *jinEDetailLabel;
@property (nonatomic,weak) UILabel *dateLabel;
@property (nonatomic,weak) UILabel *dateDetailLabel;
@property (nonatomic,weak) UILabel *statusLabel;
@property (nonatomic,weak) UILabel *statusDetailLabel;
@property (nonatomic,weak) UILabel *jiaoyiStatusLabelDetail;
@property (nonatomic,weak) UILabel *jiaoyiStatusLabel;
@property (nonatomic,weak) UILabel *yuELabel;
@property (nonatomic,weak) UILabel *yuEDetailLabel;
// 名字
@property (nonatomic,weak) UILabel *label;

@property (nonatomic,weak) UILabel *nameValueLabel;

@end
@implementation MCMMDetailPopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       
        self.frame = CGRectMake(0, kStatusBarAndNavigationBarHeight, G_SCREENWIDTH, G_SCREENHEIGHT - kStatusBarAndNavigationBarHeight);
        self.backgroundColor =  [[UIColor darkGrayColor] colorWithAlphaComponent:0.5];
         [self setUpUI];
    }
    return self;
}



- (void)setUpUI{
    UIView *popView = [[UIView alloc] init];
    popView.frame = CGRectMake(MC_REALVALUE(33), (G_SCREENHEIGHT - MC_REALVALUE(349 + 17 + kStatusBarAndNavigationBarHeight + kTabBarHeight))*0.5, G_SCREENWIDTH - MC_REALVALUE(66), MC_REALVALUE(349 + 17));
    popView.backgroundColor = [UIColor clearColor];
    [self addSubview:popView];
    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, MC_REALVALUE(17), popView.widht, popView.heiht - MC_REALVALUE(17))];
    UIImage *image = [UIImage imageNamed:@"touzhu-beijing"];
    // 设置端盖的值
    CGFloat top = image.size.height * 0.5;
    CGFloat left = image.size.width * 0.5;
    CGFloat bottom = image.size.height * 0.5;
    CGFloat right = image.size.width * 0.5;
    UIEdgeInsets edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
    // 拉伸图片
    UIImage *newImage = [image resizableImageWithCapInsets:edgeInsets];
    bgView.image = newImage;
    [popView addSubview:bgView];
    //    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 6;
    bgView.clipsToBounds = YES;
    bgView.userInteractionEnabled = YES;
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((popView.widht - MC_REALVALUE(180))*0.5, 0, MC_REALVALUE(180), MC_REALVALUE(34))];
    label.backgroundColor = RGB(82, 80, 174);
    label.text = @"xxxxx";
    label.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.layer.cornerRadius = MC_REALVALUE(17);
    label.clipsToBounds = YES;
    [popView addSubview:label];
    self.label = label;
    UIView *middleView = [[UIView alloc] init];
    [bgView addSubview:middleView];
    middleView.backgroundColor = RGB(251, 251, 251);
    middleView.layer.borderWidth = 0.5;
    middleView.layer.borderColor = RGB(220, 220, 200).CGColor;
    [middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(popView).offset(MC_REALVALUE(25));
        make.right.equalTo(popView).offset(MC_REALVALUE(-25));
        make.top.equalTo(popView).offset(MC_REALVALUE(44));
        make.bottom.equalTo(popView).offset(MC_REALVALUE(-67));
    }];
    
    
    UIButton *continueBtn = [[UIButton alloc] init];
    [bgView addSubview:continueBtn];
    continueBtn.backgroundColor = RGB(82, 80, 174);
    [continueBtn setTitle:@"我知道了" forState:UIControlStateNormal];
    [continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    continueBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    continueBtn.layer.cornerRadius = 4;
    continueBtn.clipsToBounds = YES;
    [continueBtn addTarget:self action:@selector(continueBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [continueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView);
        make.height.equalTo(@(MC_REALVALUE(34)));
        make.top.equalTo(middleView.mas_bottom).offset(MC_REALVALUE(10));
        make.width.equalTo(@(MC_REALVALUE(126)));
    }];
    UILabel *nameLabel = [[UILabel alloc] init];
    [middleView addSubview:nameLabel];
    nameLabel.text = @"用户名称：";
    nameLabel.textColor = RGB(46, 46, 46);
    nameLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    
    UILabel *nameValueLabel = [[UILabel alloc] init];
    [middleView addSubview:nameValueLabel];
    nameValueLabel.textColor = RGB(46, 46, 46);
    nameValueLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.nameValueLabel = nameValueLabel;
    nameValueLabel.numberOfLines = 0;
    
    
    UILabel *dingDanLabel = [[UILabel alloc] init];
    [middleView addSubview:dingDanLabel];
    self.dingDanNumberLabel = dingDanLabel;
    dingDanLabel.text = @"流水号：";
    dingDanLabel.textColor = RGB(46, 46, 46);
    dingDanLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    
    UILabel *dingDanDetailLabel = [[UILabel alloc] init];
    [middleView addSubview:dingDanDetailLabel];
    dingDanDetailLabel.textColor = RGB(46, 46, 46);
    dingDanDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.dingDanDetailLabel = dingDanDetailLabel;
    dingDanDetailLabel.numberOfLines = 0;
    
    UILabel *jinELabel = [[UILabel alloc] init];
    [middleView addSubview:jinELabel];
    jinELabel.text = @"交易金额：";
    jinELabel.textColor = RGB(46, 46, 46);
    jinELabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.jinELabel = jinELabel;
    
    
    UILabel *jinEDetailLabel = [[UILabel alloc] init];
    [middleView addSubview:jinEDetailLabel];
    jinEDetailLabel.textColor = RGB(249, 84, 83);
    jinEDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.jinEDetailLabel = jinEDetailLabel;
    
    
    
    UILabel *yuELabel = [[UILabel alloc] init];
    [middleView addSubview:yuELabel];
    yuELabel.text = @"剩余金额：";
    yuELabel.textColor = RGB(46, 46, 46);
    yuELabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.yuELabel = yuELabel;
    
    
    UILabel *yuEDetailLabel = [[UILabel alloc] init];
    [middleView addSubview:yuEDetailLabel];
    yuEDetailLabel.textColor = RGB(249, 84, 83);
    yuEDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.yuEDetailLabel = yuEDetailLabel;
    
    
    UILabel *jiaoyiStatusLabel = [[UILabel alloc] init];
    [middleView addSubview:jiaoyiStatusLabel];
    self.jiaoyiStatusLabel = jiaoyiStatusLabel;
    jiaoyiStatusLabel.text = @"交易类型：";
    jiaoyiStatusLabel.textColor = RGB(46, 46, 46);
    jiaoyiStatusLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    
    UILabel *statusLabelDetail = [[UILabel alloc] init];
    [middleView addSubview:statusLabelDetail];
    statusLabelDetail.textColor = RGB(46, 46, 46);
    statusLabelDetail.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.jiaoyiStatusLabelDetail = statusLabelDetail;
    
    
   
    UILabel *dateLabel = [[UILabel alloc] init];
    [middleView addSubview:dateLabel];
    dateLabel.textColor = RGB(46, 46, 46);
    dateLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    dateLabel.text = @"交易时间：";
    self.dateLabel = dateLabel;
    
    UILabel *dateDetailLabel = [[UILabel alloc] init];
    [middleView addSubview:dateDetailLabel];
    dateDetailLabel.textColor = RGB(46, 46, 46);
    dateDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.dateDetailLabel = dateDetailLabel;
    
    
    UILabel *statusLabel = [[UILabel alloc] init];
    [middleView addSubview:statusLabel];
    statusLabel.textColor = RGB(46, 46, 46);
    statusLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    statusLabel.text = @"备注：";
    self.statusLabel = statusLabel;
    
    UILabel *statusDetailLabel = [[UILabel alloc] init];
    [middleView addSubview:statusDetailLabel];
    statusDetailLabel.textColor = RGB(46, 46, 46);
    statusDetailLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.statusDetailLabel = statusDetailLabel;
    statusDetailLabel.numberOfLines = 0;
    // 用户名
    [self.dingDanNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(middleView).offset(MC_REALVALUE(20));
        make.left.equalTo(middleView).offset(MC_REALVALUE(16));
        make.width.equalTo(@(MC_REALVALUE(70)));
    }];
    [self.dingDanDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dingDanNumberLabel.mas_right);
        make.right.equalTo(middleView);
        make.top.equalTo(self.dingDanNumberLabel);
    }];

    //交易金额
    [self.jinELabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dingDanNumberLabel);
        make.top.equalTo(self.dingDanDetailLabel.mas_bottom).offset(MC_REALVALUE(15));
        make.width.equalTo(@(MC_REALVALUE(70)));
        
    }];
    [self.jinEDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.jinELabel.mas_right);
        make.top.equalTo(self.jinELabel);
    }];
//    剩余金额
    
    
    [self.yuELabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dingDanNumberLabel);
        make.top.equalTo(self.jinELabel.mas_bottom).offset(MC_REALVALUE(15));
        make.width.equalTo(@(MC_REALVALUE(70)));
        
    }];
    [self.yuEDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dateLabel.mas_right);
        make.top.equalTo(self.yuELabel);
    }];
//    交易类型
    [self.jiaoyiStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.yuELabel.mas_bottom).offset(MC_REALVALUE(15));
        make.left.equalTo(self.dingDanNumberLabel);
        make.width.equalTo(@(MC_REALVALUE(70)));
    }];
    [self.jiaoyiStatusLabelDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.jiaoyiStatusLabel.mas_right);
        make.top.equalTo(self.jiaoyiStatusLabel);
    }];
    
    

//交易时间
    
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dingDanNumberLabel);
        make.top.equalTo(self.jiaoyiStatusLabel.mas_bottom).offset(MC_REALVALUE(15));
        make.width.equalTo(@(MC_REALVALUE(70)));
    }];
    [self.dateDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.statusLabel.mas_right);
        make.top.equalTo(self.dateLabel);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dingDanNumberLabel);
        make.top.equalTo(self.dateLabel.mas_bottom).offset(MC_REALVALUE(15));
        make.width.equalTo(@(MC_REALVALUE(70)));
    }];
    [self.statusDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.statusLabel.mas_right);
        make.right.equalTo(middleView);
        make.top.equalTo(self.statusLabel);
    }];
    
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self hidden];
}

- (void)continueBtnClick{
    
    if (self.cancelBtnBlock) {
        self.cancelBtnBlock();
    }
}

- (void)show{
    self.hidden = NO;
    self.transform = CGAffineTransformMakeScale(0.05, 0.05);
    [UIView animateWithDuration:0.1 animations:^{
        self.transform = CGAffineTransformMakeScale(1, 1);
    }];
}
- (void)hidden{
    [UIView animateWithDuration:0.1 animations:^{
        self.transform = CGAffineTransformMakeScale(0.0001, 0.0001);
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

- (void)setDataSource:(MCTeamCModel *)dataSource{
    _dataSource = dataSource;
    self.label.text = [NSString stringWithFormat:@"%@账变记录",dataSource.UserName];
    self.dingDanDetailLabel.text = dataSource.OrderID;
    NSString *useMstr = [NSString stringWithFormat:@"%@",dataSource.UseMoney];
    self.jinEDetailLabel.text = GetRealSNum(useMstr);
    NSString *balanceStr = [NSString stringWithFormat:@"%@",dataSource.ThenBalance];
    self.yuEDetailLabel.text =GetRealSNum(balanceStr);
    self.dateDetailLabel.text = dataSource.InsertTime;
    self.jiaoyiStatusLabelDetail.text = [MCRecordTool getJiaoyiType:dataSource.DetailsSource and:dataSource.RechargeType andPayTypeName:dataSource.PayTypeName].name;
    MCUserAccountRecordDetailDataModel *model = [[MCUserAccountRecordDetailDataModel alloc] init];
    model.Marks = dataSource.Marks;
    model.DetailsSource = [NSString stringWithFormat:@"%d",dataSource.DetailsSource];
    self.statusDetailLabel.text = [MCUserAccountRecordDetailDataModel getMarksDetail:model];

}

@end
